//
//  OrderDescViewController.m
//  LoveFreshBeen
//
//  Created by vinsent on 16/10/21.
//  Copyright © 2016年 魏根. All rights reserved.
//

#import "OrderDescViewController.h" 
#import "StatusTVC.h"
#import "OrderdescTVC.h"
#import "MyorderViewModel.h"

@interface OrderDescViewController ()

@property(nonatomic,strong) UISegmentedControl *segement;

@property(nonatomic,strong) StatusTVC *tvc;
@property(nonatomic,strong) OrderdescTVC *ovc;
@end

@implementation OrderDescViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    [self.tabBarController.tabBar setHidden:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavigationBar];
    [self loadTableViewController];
}

- (void)setNavigationBar {
    
    self.view.backgroundColor = [UIColor lightGrayColor];
    self.title = @"草拟麻痹";
    
    NSArray *arr = @[@"订单状态",@"订单详情"];
    
    
    
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:arr];
    segment.frame = CGRectMake(0, 0,90, 30);
    
    segment.tintColor = [UIColor orangeColor];
    
    self.navigationItem.titleView = segment;
    
    self.segement = segment;
    
    [self.segement addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged];
    segment.selectedSegmentIndex = 0;
}


- (void )segmentClick:(UISegmentedControl *)sender {
    
    if (sender.selectedSegmentIndex == 1) {

        [self.tvc removeFromParentViewController];
        [self.tvc.tableView removeFromSuperview];
        
        [self addChildViewController:_ovc];
        [self.view addSubview:_ovc.tableView];
        
       
        
    } else {

        [self.ovc removeFromParentViewController];
        [self.ovc.tableView removeFromSuperview];
        
            [self addChildViewController:_tvc];
            [self.view addSubview:_tvc.tableView];
        
    
        
    }
}

- (void)loadTableViewController {
    
    StatusTVC *tvc = [[StatusTVC alloc] init];
    OrderdescTVC *ovc = [[OrderdescTVC alloc] initWithStyle:UITableViewStyleGrouped];

    [self addChildViewController:tvc];
    [self.view addSubview:tvc.tableView];
    self.tvc = tvc;
    self.ovc = ovc;

    ovc.index = self.index;
    tvc.statusVModel.statuses = [MyorderViewModel sharedMyorder].myorders[self.index].myorderModel.status_timeline;
}

- (void)loadOrderDescTableViewController {
    
    OrderdescTVC *tvc = [[OrderdescTVC alloc] initWithStyle:UITableViewStyleGrouped];
    
    [self addChildViewController:tvc];
    [self.view addSubview:tvc.tableView];
    
    tvc.index = self.index;
    
}

@end
